import { configureStore, PayloadAction, Store } from '@reduxjs/toolkit';
import authReducer, { AuthState } from './authSlice';
import coinReducer, { CoinState } from './coinSlice';
import basedataReducer, { BasedataState } from './basedataSlice';
import rebateReducer, { RebateState } from './rebateSlice';
// import settingReducer, { SettingState } from './settingSlice';
import uiReducer, { UiState } from './uiSlice';

export type RootState = {
  auth: AuthState;
  coin: CoinState;
  rebate: RebateState;
  //   setting: SettingState;
  ui: UiState;
  basedata: BasedataState
};

let store: Store<RootState>;

export const configStore = () => {
  store = configureStore({
    reducer: {
      auth: authReducer,

      coin: coinReducer,
      rebate: rebateReducer,
      //   setting: settingReducer,
      ui: uiReducer,
      basedata: basedataReducer,
    },
  });

  return store;
};

export const getState = () => store.getState();

export const dispatch = <T>(action: PayloadAction<T>) => store.dispatch(action);
